

#include "mcu_dda_modbus_driver.h"

McuDdaModBusDriver::McuDdaModBusDriver(int uart_id,uint8_t slaveAddr, DWORD baudrate, BOOL is485, BOOL isLeader,WORD teamCount)
{
	m_commDriver = new McuCommDriver(uart_id, baudrate,FALSE, is485);
	m_modbusSlaver = new McuModbusSlaver(m_commDriver,slaveAddr, isLeader, teamCount);
	m_comDriverListen = new CxReturn();
	this->Start();
}

McuDdaModBusDriver::~McuDdaModBusDriver()
{
	delete m_modbusSlaver;
	delete m_commDriver;
	delete m_comDriverListen;
}



void McuDdaModBusDriver::Close()
{
	SyncStop(200);

	return;
}





void McuDdaModBusDriver::Run(void)
{
	while (TRUE) {
		if (m_comDriverListen->Pend(200)) {
			if (m_modbusSlaver->Import(m_commDriver->m_rxBuf, m_commDriver->m_rxBufLen)) {
				m_modbusSlaver->Exec();
			}
		}
		if (m_stopSignal) {
			break;
		}
	}
	m_stopReturn->Post();
	m_running = FALSE;
	osThreadExit();
}
